home *** CD-ROM | disk | FTP | other *** search
/ Freelog 46 / Freelog046.iso / Alu / Celestia / Win32LoresTex / celestia-lores-win32-1.3.0.exe / {app} / shaders / bumphaze_arb.vp < prev    next >
Text File  |  2003-03-05  |  2KB  |  80 lines

  1. !!ARBvp1.0
  2.  
  3. # Compute the surface space light vectors for diffuse bump mapping
  4. # as well as a fog factor for an atmospheric haze effect.
  5.  
  6. ATTRIB iPos          = vertex.position;
  7. ATTRIB iNormal       = vertex.normal;
  8. ATTRIB iTangent      = vertex.attrib[6];
  9. ATTRIB iTex0         = vertex.texcoord[0];
  10. ATTRIB iTex1         = vertex.texcoord[1];
  11. PARAM  mvp[4]        = { state.matrix.mvp };
  12. PARAM  eyePos        = program.env[1];
  13. PARAM  lightDir      = program.env[0];
  14. PARAM  haze          = program.env[6];
  15. PARAM  half          = 0.5;
  16. PARAM  zero          = 0;
  17. PARAM  one           = 1;
  18. OUTPUT oPos          = result.position;
  19. OUTPUT oColor        = result.color;
  20. OUTPUT oTex0         = result.texcoord[0];
  21. OUTPUT oTex1         = result.texcoord[1];
  22. OUTPUT oFog          = result.fogcoord;
  23.  
  24. TEMP   binormal;
  25. TEMP   t;
  26. TEMP   light_surf;
  27. TEMP   diffuseFactor;
  28. TEMP   eyeVec;
  29.  
  30. # Transform the vertex by the modelview matrix
  31. DP4   oPos.x, mvp[0], iPos;
  32. DP4   oPos.y, mvp[1], iPos;
  33. DP4   oPos.z, mvp[2], iPos;
  34. DP4   oPos.w, mvp[3], iPos;
  35.  
  36. # Compute the diffuse light component
  37. DP3   diffuseFactor, iNormal, lightDir;
  38. # Clamp the diffuse component to zero
  39. MAX   diffuseFactor, diffuseFactor, zero;
  40.  
  41. # Get the vector from the eye to the vertex
  42. SUB   eyeVec, eyePos, iPos;
  43.  
  44. # Normalize it
  45. DP3   eyeVec.w, eyeVec, eyeVec;
  46. RSQ   eyeVec.w, eyeVec.w;
  47. MUL   eyeVec, eyeVec, eyeVec.w;
  48.  
  49. # Output the fog factor
  50. DP3   diffuseFactor.y, iNormal, eyeVec;
  51. SUB   diffuseFactor.y, one, diffuseFactor.y;
  52. MUL   oFog.x, diffuseFactor.x, diffuseFactor.y;
  53.  
  54. # Haze is complete; now do the bump mapping setup
  55.  
  56. # Compute the binormal--cross product of normal and tangent
  57. MOV   t, iTangent;
  58. MUL   binormal, iNormal.zxyw, t.yzxw;
  59. MAD   binormal, iNormal.yzxw, t.zxyw, -binormal;
  60.  
  61. # Normalization should not be necessary
  62. #DP3   binormal.w, binormal, binormal;
  63. #RSQ   binormal.w, binormal.w;
  64. #MUL   binormal.xyz, binormal, binormal.w;
  65.  
  66. # Transform the light direction from object space into surface space
  67. DP3   light_surf.x, iTangent, lightDir;
  68. DP3   light_surf.y, binormal, lightDir;
  69. DP3   light_surf.z, iNormal, lightDir;
  70.  
  71. # Compress the light direction to fit in the primary color and output it
  72. MAD   oColor, light_surf, half, half;
  73.  
  74. # Output the texture
  75. MOV   oTex0, iTex0;
  76. MOV   oTex1, iTex1;
  77.  
  78. END
  79.  
  80.